const web = require("../../module/web"), loger = require("../../module/loger");

let rd = 0;
module.exports.run = (yzm)=>{
	web.run((w)=>{
		let inp = w.window.document.getElementsByName("account");
		if(inp && inp[0]) inp[0].value = global.sdObj.ud[3];
		inp = w.window.document.getElementsByName("password");
		if(inp && inp[0]) inp[0].value = global.sdObj.ud[10];
		inp = w.window.document.getElementsByClassName("quc-input quc-input-captcha");
		if(inp && inp[0]) inp[0].value = yzm;
		inp = w.window.document.getElementsByClassName("quc-nextAndGet-sms-token");
		if(inp && inp[0]) inp[0].click();
	}, (w)=>{ //页面重新加载后准备输入验证码
		loger.info("input yzm");
		let inp = w.window.document.getElementsByClassName("quc-button quc-button-sign-up");
		if(inp && inp[0] && inp[0].clientWidth > 0) {
			global.sdObj.end = 0;
			return true;
		}
		inp = w.window.document.getElementsByClassName("quc-tip quc-tip-error");
		for(let i=0;i<inp.length;i++){
			if(inp[i].innerHTML.indexOf("该手机号已经注册") != -1){
				global.sdObj.end = 1030;
				return true;
			}else if(inp[i].innerHTML.indexOf("网络错误") != -1){ //再次点击注册按钮
				inp = w.window.document.getElementsByClassName("quc-nextAndGet-sms-token");
				if(inp && inp[0]) inp[0].click();
				return;
			}else if(inp[i].innerHTML.indexOf("验证码错误请重新输入") != -1){
				rd++;
				if(rd > 2){
					global.sdObj.end = 1034;
					rd = 0;
					return true;
				}
				web.getImg("tmp", 3, ()=>{
					global.sdObj.end = -99;
				})
				return true;
			}
		}
	})
}